package 可重入锁.用阻塞队列的生产者消费者;

import java.util.concurrent.BlockingQueue;

public class Consumer implements Runnable {
    BlockingQueue<Integer> queue;

    public Consumer(BlockingQueue<Integer> queue) {
        this.queue = queue;
    }


    @Override
    public void run() {
        while (true) {
            Integer take;
            try {
//                take = queue.take();
                take = queue.poll();
                if (take != null)
                    System.out.println(Thread.currentThread().getName() + " 拿到 " + take);
                else
                    System.out.println(Thread.currentThread().getName() + " 等待");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
